<?php
class SystemUtil {

  public static function cleanOldFiles($directory, $expiry = 3600) {
    $c = 0;
    $dp = @opendir($directory);
    if ($dp) {
      while ($file = @readdir($dp)) {
        if ($file != '.' && $file != '..' && is_writable($directory . '/' . $file) && (filemtime($directory . '/' . $file)) < (time() - $expiry)) {
          if (@unlink($directory . '/' . $file)) {
            $c++;
          }
        }
      }
      @closedir($dp);
    }
    return $c;
  }

  public static function arrayFlatten($array) {
    if (!is_array($array)) {
      return false;
    }
    $rslt = array();
    foreach ($array as $key => $val) {
      if (is_array($val)) {
        $rslt = array_merge($rslt, self::arrayFlatten($val));
      } elseif (is_int($key)) {
        $rslt[] = $val;
      } else {
        $rslt[$key . uniqid()] = $val;
      }
    }
    return $rslt;
  }
}